package com.java01;

public class thirteenthjava {
    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < arr.length;i++){
            arr[i] =(int) (Math.random()*100)+1;
        }
        System.out.println("==========打印===========");
        for (int value : arr){
            System.out.print(value+"\t");
        }
        System.out.println("\n=========倒序打印==========");
        for (int i = arr.length-1; i >= 0;i--){
            System.out.print(arr[i]+"\t");
        }
        System.out.println("\n=========平均值===========");
        double sum = arr[0];
        int max = arr[0];
        int maxindex = 0;
        for (int i = 1;i<arr.length;i++){
            if (max < arr[i]){
                max = arr[i];
                maxindex = i;
            }
            sum += arr[i];
        }
        System.out.println("max="+ max +",index="+maxindex);
        System.out.println("平均值="+(sum/arr.length));
        int findnum = 8,index = -1;
        for (int i = 0;i<arr.length;i++){
            if (arr[i]==findnum){
                index = i;
                System.out.println("数组中有8这个数字,下标为"+index);
                break;
            }
        }
        if (index == -1){
            System.out.println("数组中没有8这个数字。");
        }
    }
}
class homework{
    public static void main(String[] args) {
        int[] arr = {10,90,23,46,25};
        int temp;
        for (int i = 0;i<arr.length-1;i++){
            for (int j = 0 ; j < arr.length - 1 - i ; j++) {
                if (arr[j] > arr[j + 1]) {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;

                }
            }
        }
        for (int value :arr){
            System.out.print(value+"\t");
        }
    }
}
